<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>初始化并跳转</title>
    <script src="../jquery-3.5.1.min.js"></script>
    <script type="text/javascript">
        // 显示加载层
        function showLoading() {
            $('#loading-overlay').fadeIn(200);
        }

        // 隐藏加载层
        function hideLoading() {
            $('#loading-overlay').fadeOut(200);
        }

        // 示例：模拟异步操作
        $(document).ready(function () {
            showLoading();
        });


        var setCookie = function (name, value, days) {
            var expires = "";
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                expires = "; expires=" + date.toUTCString();
            }
            document.cookie = name + "=" + (value || "") + expires + "; path=/";
        }

        // 页面加载完成后执行
        var getUrlParam = function (name) {
            var url = location.search;
            url = url.substring(url.indexOf("?"));
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                //console.log(strs);
                for (var i = 0; i < strs.length; i++) {
                    if (name == strs[i].split("=")[0]) {
                        if (name.indexOf("Data") > -1) {
                            return decodeURIComponent(strs[i].split("=")[1]);
                        }
                        else {
                            return unescape(strs[i].split("=")[1]);
                        }
                    }
                }
            }
            return "";
        }

        window.onload = function () {
            var formData = new FormData();

            // 添加文本字段
            formData.append('captchId', 'Snbrjf0J1743228703143');
            formData.append('state', '');
            formData.append('username', getUrlParam("username"));
            formData.append('client_id', 'web');
            formData.append('password', getUrlParam("pwd"));
            formData.append('sid', '9A4C81B9-78DF-4167-89C9-587463A6DA92');
            formData.append('eid', 1);

            $.ajax({
                url: '../api/v1/account/login?redirect=%2Fdashboard',
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (response) {
                    console.log(response); 
                    localStorage.setItem('client-9A4C81B9-token', 'Bearer ' + response.data.access_token);
                    localStorage.setItem('client-9A4C81B9-expires', parseInt(getUrlParam("d")));
                    localStorage.setItem('client-9A4C81B9-refreshToken', response.data.refresh_token);
                    localStorage.setItem('client-9A4C81B9-improve', undefined);
                    localStorage.setItem('client-solutionId', "9A4C81B9-78DF-4167-89C9-587463A6DA92");
                    localStorage.setItem('defaultPercent', 12.037449843958983);
                    localStorage.setItem('improve-9A4C81B9-pwd', "");
                    localStorage.setItem('improve-pwd', "");
                    localStorage.setItem('useCookie', true);
                    localStorage.setItem('solution-list', [{ "id": "9A4C81B9", "fullId": "9A4C81B9-78DF-4167-89C9-587463A6DA92" }]);
                    localStorage.setItem('loginForm', { "username": getUrlParam("username"), "password": getUrlParam("pwd"), "solution": "9A4C81B9-78DF-4167-89C9-587463A6DA92", "state": "", "captchId": "4NweSUyL1741398800694" });

                    // 设置值
                    sessionStorage.setItem('vuex', { "app": { "clientColor": "#72777D", "menuSize": "normal", "language": "zh", "OEMInfo": { "ProductShortName": "Workfine", "CompanyEnglishName": "Wuxi Benniu Co.,Ltd.", "CompanyHomePage": "https://www.bn100.com", "CompanySupport": "https://community.bn100.com" }, "sidebar": { "opened": true, "withoutAnimation": false }, "themeName": "default", "theme": { "value": "default", "main": "#409EFF", "slideColor": "#304156", "textColor": "#ffffff", "slideActiveColor": "#f0f0f0", "headerColor": "#222632", "name": "默认皮肤", "type": 1 }, "customThemes": { "default": { "value": "default", "main": "#409EFF", "slideColor": "#304156", "textColor": "#ffffff", "slideActiveColor": "#f0f0f0", "headerColor": "#222632", "name": "默认皮肤", "type": 1 }, "custom": { "value": "custom", "main": "#409EFF", "slideColor": "#304156", "textColor": "#ffffff", "slideActiveColor": "#f0f0f0", "headerColor": "#222632", "name": "自定义皮肤", "type": 2 }, "red": { "value": "red", "main": "#F5646C", "slideColor": "#F5646C", "textColor": "#ffffff", "slideActiveColor": "#ffffff", "headerColor": "#F5646C", "name": "红", "type": 2 }, "young": { "value": "young", "main": "#63D8D2", "slideColor": "#63D8D2", "textColor": "#ffffff", "slideActiveColor": "#ffffff", "headerColor": "#63D8D2", "name": "青", "type": 2 }, "green": { "value": "green", "main": "#259C6A", "slideColor": "#259C6A", "textColor": "#ffffff", "slideActiveColor": "#ffffff", "headerColor": "#259C6A", "name": "绿", "type": 2 }, "orange": { "value": "orange", "main": "#FFAE00", "slideColor": "#FFAE00", "textColor": "#ffffff", "slideActiveColor": "#ffffff", "headerColor": "#FFAE00", "name": "橙", "type": 2 }, "blue": { "value": "blue", "main": "#0991EB", "slideColor": "#0991EB", "textColor": "#ffffff", "slideActiveColor": "#ffffff", "headerColor": "#0991EB", "name": "蓝", "type": 2 }, "purple": { "value": "purple", "main": "#A05AD9", "slideColor": "#A05AD9", "textColor": "#ffffff", "slideActiveColor": "#ffffff", "headerColor": "#A05AD9", "name": "紫", "type": 2 }, "ywcq": { "value": "ywcq", "main": "#78A3E7", "slideColor": "#FFFFFF", "textColor": "#204D95", "slideActiveColor": "#204D95", "headerColor": "#204D95", "fastCardColor": "#F8C975", "name": "仰望苍穹", "type": 3 }, "qqzj": { "value": "qqzj", "main": "#118FA8", "slideColor": "#FAFAF5", "textColor": "#1E6B8F", "slideActiveColor": "#1E6B8F", "headerColor": "#118FA8", "fastCardColor": "#F5D193", "name": "青青子衿", "type": 3 }, "fyhl": { "value": "fyhl", "main": "#FFB2B2", "slideColor": "#FFFFFF", "textColor": "#804040", "slideActiveColor": "#804040", "headerColor": "#804040", "fastCardColor": "#93C4F5", "name": "枫叶红了", "type": 3 } }, "device": "desktop", "defaultPercent": 14, "disableTree": false, "showRefresh": false, "backgroundColor": "#0991EB", "textColor": "#ffffff", "activeTextColor": "#409EFF", "logoBackgroundColor": "#222632", "formFilter": null, "temporaryId": null, "copyCreateRID": null, "onlyOfficeSetting": { "active": false }, "fontList": [] } });

                    //setCookie("sidebarStatus", 1, 1);
                    //console.log(token);
                    hideLoading();//隐藏
                    var url = "../index.html#/preview/" + getUrlParam("id") + "/0?sid=9A4C81B9 ";
                    // 2. 跳转到指定 URL
                    window.location.href = url;
                },
                error: function (xhr, status, error) {
                    window.location.href = "../index.html#/login?redirect=%2Fdashboard&sid=9A4C81B9";
                    // 请求失败时的回调函数
                    //  alert('Error: ' + error); // 显示错误信息
                }
            });


        };</script>
    <style>
        #loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            display: none; /* 默认隐藏 */
            justify-content: center;
            align-items: center;
            z-index: 9999;
        }

        .loading-container {
            text-align: center;
            color: #fff;
            padding-top: 25%;
        }

        .spinner {
            width: 40px;
            height: 40px;
            margin: 0 auto 10px;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }
    </style>
</head>
<body>
    <!-- 加载层容器 -->
    <div id="loading-overlay">
        <div class="loading-container">
            <div class="spinner"></div>
            <div>数据加载中...</div>
        </div>
    </div>

</body>
</html>